﻿using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Collisions;


namespace XNA_3DFramWork
{
    public class Mesh : VisualObject
    {
        private readonly Camera _camera;
        private readonly Model _model;
        public Body BodyXY;
        public Body BodyYZ;
        public Body BodyXZ;
        public Geom GeomXY;
        public Geom GeomYZ;
        public Geom GeomXZ;
        public Mesh(Game game, string fileName, Camera camera
            ,Vector3 Position   , PhysicsSimulator physicsSimulator)
            : base(game)
        {
            Postion = Position;
            _model = new Model();
            _camera = camera;
            Matrix = Matrix.Identity;
            _model = game.Content.Load<Model>(fileName);
            BodyXY = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 10, 10, 1);
            BodyXY.Position = new Vector2(Postion.X, Postion.Y);
            GeomXY = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, BodyXY, 10, 10);
           
            BodyYZ = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 10, 10, 1);
            BodyYZ.Position = new Vector2(Postion.Y, Postion.Z);
            GeomYZ = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, BodyYZ, 10, 10);
            
            BodyXZ = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 10, 10, 1);
            BodyXZ.Position = new Vector2(Postion.X, Postion.Z);
            GeomXZ = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, BodyXZ, 10, 10);

        }
        public override void Draw()
        {
            foreach (ModelMesh mesh in _model.Meshes)
            {
                foreach (BasicEffect currentEffect in mesh.Effects)
                {
                    currentEffect.EnableDefaultLighting();
                    currentEffect.View =_camera.Matrix;
                    currentEffect.Projection = _camera.BEffect.Projection;
                    currentEffect.World = Matrix;
                }
                mesh.Draw();
            }
        }
        public override void Update()
        {
            
        }
    }
}